package com.exsun.ex1077.ui.activity.mine

import androidx.databinding.ObservableField
import androidx.lifecycle.MutableLiveData
import com.exsun.ex1077.extend.toPhotoUrl
import com.exsun.ex1077.network.apiService
import com.exsun.ex1077.network.entity.ServiceTel
import com.zhangping.fastjetpack.base.BaseViewModel
import com.zhangping.fastjetpack.extend.base.ResultState
import com.zhangping.fastjetpack.extend.base.request
import com.zhangping.fastjetpack.extend.putCache
import com.zhangping.fastjetpack.extend.toFileFormPart

/**
 * 描述：
 * 作者：ZhangPing
 * 创建时间：2022/5/9 16:29
 */
class MineViewModel: BaseViewModel() {

    val username = ObservableField("")
    val companyName = ObservableField("")
    val photo = ObservableField("")

    val serviceTelResult = MutableLiveData<ResultState<ServiceTel?>>()

    fun loadData(){
        request({ apiService.serviceTel()}, serviceTelResult)
    }

    fun headUpload(path: String){
        request({ apiService.headUpload( path.toFileFormPart())}, {
            if (it.isNullOrEmpty()) return@request
            "photo".putCache(it.toPhotoUrl())
            photo.set(it.toPhotoUrl())
        }, {}, true)
    }
}